<?php
	include('functions.php');
	$idcongress = getValor('idcongress');
	$congress = NULL;
	if ($idcongress == "") {
		echo "NO ID CONGRESS HAS BEEN SELECTED<BR>";
	} else {	
		$congress = obtenerCongress($idcongress);
	}
	
	$codeerror = false;
	
	if (isset($_POST['login']) && $_POST['login'] == 'login') {
		$keycongress = getValor('keycongress');
		$idcongress = $_POST['idcongress'];

		if ($congress['LOGIN_KEY_REQUIRED'] == 0 || validarKeyCongress($keycongress, $idcongress)) {
			if (isset($_SESSION)) {
				session_destroy();
			} else {
				session_start();
			}
			$_SESSION['logged'] = true;
			$_SESSION['idcongress'] = $idcongress;
			header("Location: congress_welcome.php");
		} else {
			$codeerror = true;
		}

	}
	
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
	<title>
		<?php echo $congress['NAME']; ?>
	</title>
	<link href="style.css" rel="stylesheet" type="text/css" media="screen" />
</head>

<body>
<div align="center">
	<table cellpadding="0" cellspacing="0" border="0">
		<tr>
			<td colspan="2" background="">
				<img src="images/congress_login/<?php echo $congress['LOGIN_HEADER']; ?>" />
			</td>
		</tr>
		<tr>
			<td>
				<img src="images/congress_login/<?php echo $congress['LOGIN_LEFT_PANEL']; ?>" />
			</td>
			<td>
				<form action="congress_login.php" method="post">
				<table cellpadding="2">
					<?php if ($codeerror) { ?>
					<tr>
						<td>
							<span style="color: red; font-weight:bold;">WRONG LOGIN KEY</span>
						</td>
					</tr>
					<?php } ?>
					
					<?php if ($congress['LOGIN_KEY_REQUIRED'] == 1) { ?>
					<tr>
						<td align="right">
							<span class="loginkey">LOGIN KEY</span>
						</td>
					</tr>
					
					<tr>
						<td align="center">
							<input name="keycongress" type="text" style="width:200px;" />
						</td>
					</tr>
					<?php } ?>
					<tr>
						<td align="center">
							<input type="submit" value="Enter" style="width:200px;"  />
						</td> 
					</tr>
				</table>
				
				<input type="hidden" name="idcongress" value="<?php echo $congress['ID_CONGRESS']; ?>"  />
				<input type="hidden" name="login" value="login"  />
				
				</form>
			</td>
		</tr>
		<tr>
			<td colspan="2" background="images/congress_login/<?php echo $congress['LOGIN_FOOTER']; ?>" 
				style="height: 171px; vertical-align: bottom;" align="left">
				<a style="padding-left:20px;" href="password_forgot.php?idcongress=<?php echo $congress['ID_CONGRESS']; ?>">Forgot your password</a>
			</td>
		</tr>
	</table>
</div>
</body>
</html>